#include "pagecontrol.h"

#include <QDebug>
#include <QGraphicsProxyWidget>
#include <QAction>
#include <KIcon>

#include "page.h"
#include <qpainter.h>

PageControl::PageControl(Page *parent): QObject(parent), QGraphicsItem((QGraphicsItem*)parent)
{
    // TODO: Remove ZValue - only used for debugging.
    setZValue(2);
    m_toolBarProxy = 0;
    // Parent of the toolbar is 0, and will be set later by the QGraphicsProxyWidget.
    m_toolBarWidget = new QToolBar(0);

    // TODO: Where to define the actions?
    QAction *action = m_toolBarWidget->addAction(KIcon("archive-insert"), "Append a new page after this.");
    connect(action, SIGNAL(triggered()), parent, SLOT(addPageAfter()));

    action = m_toolBarWidget->addAction(KIcon("go-up"), "Move this page up.", parent, SLOT(moveUp()));
    action = m_toolBarWidget->addAction(KIcon("go-down"), "Move this page down.", parent, SLOT(moveDown()));
    action = m_toolBarWidget->addAction(KIcon("archive-remove"), "Remove this page.", parent, SLOT(remove()));
    action = m_toolBarWidget->addAction(KIcon("edit-copy"), "Duplicate this page.", parent, SLOT(duplicate()));

    // Create the proxy object that can be displayed in the scene.
    m_toolBarProxy = new QGraphicsProxyWidget(this);
    m_toolBarProxy->setWidget(m_toolBarWidget);
}

void PageControl::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
{
    // FIXME: Graphics object has a black background and looks like ass.
}

QRectF PageControl::boundingRect() const
{
    return m_toolBarProxy->boundingRect();
}

